package com.example.demo.controller;

import com.example.demo.pojo.Register;
import com.example.demo.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller("mainController")
public class mainController {
    @Autowired
    RegisterService registerservice;

    @RequestMapping("/tohome")
    public String toHome() {
        return "home";
    }

    //显示is_handel =1 doctor_id的患者
    @PostMapping("/showregister")
    @ResponseBody
    public List<Register> show(@RequestBody Register register, HttpSession session){
        String doctor_id = (String) session.getAttribute("username");
        register.setDoctor_id(doctor_id);
        return registerservice.showall(register.getDoctor_id());
    }

    @PostMapping("/updatebyid")
    @ResponseBody
    public int updatebyid(@RequestBody Register register){
        int flag = registerservice.updateRegisterbyid(register.getId());
        return flag;
    }
}
